﻿@using System.Web.Script.Serialization
@{
    ViewBag.Title = "ShipOrder"; 
    Layout = "~/views/shared/_Layout.cshtml";
}

<h2>ShipOrder</h2>


<span data-bind="text:OrderId"></span>
<label>tracking no</label>
<input type="text" data-bind="value:TrackingNo"/>
<input type="button" data-bind="click:ShipOrder" value="Ship order"/>



@{
    var model = ViewBag.Model;

    var jsonStr = new HtmlString(new JavaScriptSerializer().Serialize(model));
}



@section scripts{
    
    <script>
        var init = @jsonStr;


        function ShipOrderModel() {
            var self = this;
            self.OrderId = ko.observable(init.OrderId);
            self.TrackingNo = ko.observable();

            self.ShipOrder = function() {
                $.ajax({
                    url: "/api/ShippingApi/SetOrderShipping",
                    type: 'post',
                    data: ko.toJSON(self),
                    contentType: 'application/json',
                    success: function(result) {

                        if (result.Status == "0") {
                            alert("保存成功");
                            //location.href = '' + result.Id;
                        } else {
                            alert("保存失败：" + result.Msg);
                        }
                    }
                });
            };
        }

        var vm = new ShipOrderModel();
        ko.applyBindings(vm);
    </script>
    }

